package com.hc.wdj.core;

import com.hc.wdj.core.context.HcContext;
import com.hc.wdj.core.context.HcContextDefaultImpl;

/**
 * @author ryanwdj
 * @since 2024/11/17
 */
public class HcManager {

    /**
     * 一级上下文 HcContext
     */
    private volatile static HcContext hcContext;
    /**
     * 二级上下文 HcSecondContext
     */
    private volatile static HcContext hcSecondContext;
    public static HcContext getHcContextOrSecond(){
        // 1、一级context可用时，返回一级context
        if(hcContext != null){
            if(hcSecondContext == null || hcContext.isValid()){
                return hcContext;
            }
        }
        // 2、一级context不可用时判断二级context是否可用
        if(hcSecondContext != null && hcSecondContext.isValid()){
            return hcSecondContext;
        }
        // 3、都不行，就返回默认的context
        return HcContextDefaultImpl.defaultContext;
    }
}
